<template>
  <div class="follows">
    <nav-top title="我的关注" />
    <div class="follow-list">
      <div class="follow" v-for="item of follows" :key="item.id">
        <img v-if="item.head_img" :src="$axios.defaults.baseURL + item.head_img" alt class="avatar" />
        <img v-else src="@/assets/logo.png" alt class="avatar" />
        <div class="info">
          火星情报局
          <div class="date">2010-02-02</div>
        </div>
        <div class="btn" @click="cancelFollow(item.id)">取消关注</div>
      </div>
    </div>
    <van-empty v-if="!follows.length" image="error" description="您还没有关注任何用户" />
  </div>
</template>

<script>
import NavTop from "../../components/NavTop";
export default {
  name: "Follows",
  components: {
    NavTop,
  },
  data() {
    return {
      follows: [],
      isFollow: true,
    };
  },
  mounted() {
    this.getFollows();
  },
  methods: {
    getFollows() {
      this.$axios.get("/user_follows").then((res) => {
        this.follows = res.data.data;
      });
    },
    cancelFollow(id) {
      this.$axios.get("/user_unfollow/" + id).then((res) => {
        this.getFollows();
      });
    },
  },
};
</script>

<style scoped lang="less">
.follows {
  .follow {
    display: flex;
    align-items: center;
    padding: 16/360 * 100vw;
    border-bottom: 1px solid #e4e4e4;
    .avatar {
      width: 40/360 * 100vw;
      height: 40/360 * 100vw;
      border-radius: 50%;
      object-fit: cover;
    }
    .info {
      flex: 1;
      padding-left: 10/360 * 100vw;
      font-size: 16/360 * 100vw;
      .date {
        font-size: 14/360 * 100vw;
        padding-top: 4/360 * 100vw;
        color: #888;
      }
    }
    .btn {
      background: #e4e4e4;
      font-size: 13/360 * 100vw;
      height: 32/360 * 100vw;
      line-height: 32/360 * 100vw;
      padding: 0 12/360 * 100vw;
      border-radius: 16/360 * 100vw;
    }
  }
}
</style>
